/**
* @file   wrapper.c
* @author sunway <sunwayforever@gmail.com>
* @date   Wed Oct 29 16:46:44 2008
* 
* @brief  
* 
* 
*/
#include "wrapper.h"
#include <error.h>
#include <stdlib.h>

int Socket(int domain, int type, int protocol) {
    int ret=socket (domain,type,protocol);
    if (ret==-1) {
	perror ("error when Socket");
	exit (1);
    } else {
	return ret;
    }
}

int Bind(int socket, const struct sockaddr *address,socklen_t address_len) {
    int ret=bind(socket, address,address_len);
    if (ret==-1) {
	perror ("error when Bind");
	exit (1);
    } else {
	return ret;
    }
}

ssize_t Recvfrom (int s, void *buf, size_t len, int flags,struct sockaddr *from, socklen_t *fromlen) {
    ssize_t ret=recvfrom (s, buf, len, flags,from, fromlen);
    if (ret==-1) {
	perror ("error when Recvfrom");
	exit (1);
    } else {
	return ret;
    }
}

ssize_t Sendto(int socket, const void *message, size_t length,int flags, const struct sockaddr *dest_addr,socklen_t dest_len) {
    ssize_t ret=sendto(socket, message, length, flags, dest_addr, dest_len);
    if (ret==-1) {
	perror ("error when Sendto");
	exit (1);
    } else {
	return ret;
    }
}

int Listen (int socket,int backlog) {
    int ret=listen (socket,backlog);
    if (ret==-1) {
	perror ("error when Listen");
	exit (1);
    } else {
	return ret;
    }
}
